package dhm.com.dhmshop.adapter.home;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.GetOneCategory;
import dhm.com.dhmshop.framework.base.MyBaseViewHolder;
import dhm.com.dhmshop.framework.module.commodity.entity.OneGoodsEntity;
import dhm.com.dhmshop.framework.module.home.activity.ListHotGoodsActivity;
import dhm.com.dhmshop.framework.module.type.fragment.TypeCategoryChildFragment;
import dhm.com.dhmshop.framework.utils.StringUtil;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class ClassFicationAdapter extends RecyclerView.Adapter<ClassFicationAdapter.ViewHolder> {

    private List<GetOneCategory.ChildCategory.DataBean> shopList;
    private Context context;


    public ClassFicationAdapter(Context context) {
        this.shopList = new ArrayList<>();
        this.context = context;
    }


    public void setShopList(List<GetOneCategory.ChildCategory.DataBean> shopList) {
        this.shopList = shopList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_type, viewGroup,false);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.title_typechild.setText(shopList.get(i).getName()+"");

        TypeCategoryAdapter typeCategoryAdapter= new TypeCategoryAdapter();

        viewHolder.recyclerview_typechild.setAdapter(typeCategoryAdapter);
        typeCategoryAdapter.addData(shopList.get(i).getChild());
    }

    @Override
    public int getItemCount() {
        return shopList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView title_typechild;
        public RecyclerView recyclerview_typechild;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            title_typechild=itemView.findViewById(R.id.title_typechild);
            recyclerview_typechild=itemView.findViewById(R.id.recyclerview_typechild);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int posttion, int num);
    }

    private OnShopClick onshopClick;
    public void setaddClick(OnShopClick onClick) {
        this.onshopClick= onClick;
    }
    public interface OnShopClick{
        void item(int posttion);
    }

    /**
     * 热门商品内部适配器
     */
    public  class TypeCategoryAdapter extends BaseQuickAdapter<GetOneCategory.ChildCategory.DataBean.ChildBean, MyBaseViewHolder> {
        public TypeCategoryAdapter() {
            super(R.layout.classificationitem);
        }

        @Override
        protected void convert(MyBaseViewHolder helper, GetOneCategory.ChildCategory.DataBean.ChildBean item) {
            helper.setText(R.id.tv_typechild, StringUtil.preventNull(item.getSimpleName()));
            SimpleDraweeView iv_typechild = helper.getView(R.id.iv_typechild);
            iv_typechild.setImageURI(Constant.PATH+"/"+item.getCatImg());
            helper.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, ListHotGoodsActivity.class);
                    intent.putExtra("goods_name", item.getSimpleName());
                    intent.putExtra("cate_id", item.getCatId());
                    context.startActivity(intent);
                }
            });
        }
    }

}

